#include "ControlePintor.h"
#include "ControlePrincipal.h"
#include <SDL/SDL.h>
#include <GL/glew.h>

ControlePintor::ControlePintor(){

}

ControlePintor::~ControlePintor(){

}

void ControlePintor::initSDL(int width, int height){
    SDL_Init(SDL_INIT_EVERYTHING); //inicia todas a funcoes SDL

    int flags 	 =	SDL_OPENGL;
    flags	    |=	SDL_GL_DOUBLEBUFFER;
    flags	    |=	SDL_HWPALETTE;
    flags	    |=	SDL_RESIZABLE;
    flags	    |=	SDL_SWSURFACE;

    const SDL_VideoInfo *videoInfo = SDL_GetVideoInfo();

    if (!videoInfo) {
        ::exit(1);
    }

    if (videoInfo->hw_available) flags |= SDL_HWSURFACE;
    else flags |= SDL_SWSURFACE;

    if (videoInfo->blit_hw) flags |= SDL_HWACCEL;


    SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);

    SDL_Surface* screen = SDL_SetVideoMode(width, height, 16, flags);

    SDL_EnableKeyRepeat(10, 100);
}

void ControlePintor::initGL(){
    glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
    glClearDepth(1.0f);
    glEnable(GL_DEPTH_TEST);
    glDepthFunc(GL_LEQUAL);
    glShadeModel(GL_SMOOTH);
    glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
}

void ControlePintor::atualiza(){
    checkEvent(e);
    _pintor->desenha();
}